package com.cuit.riskassessment.action.project;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.riskassessment.service.ProjectService;
import com.cuit.riskassessment.util.Result;
import com.cuit.riskassessment.vo.Project;

/**
 * project 操作的相关请求
 * @author Yang_Zhiqin-pc
 *
 */
@Controller
@RequestMapping(value="project")

public class ProjectAction {

	@Autowired
	@Resource(name="projectService")
	private ProjectService projectService;
	/**
	 * 添加项目
	 * @param response
	 * @param p
	 * @return
	 */
	@RequestMapping(value="/addproject")
	public  @ResponseBody Object addProject(HttpServletResponse response ,Project p)
	{
		response.setHeader("Accept",  "application/json");
		String message =new String("操作成功！");
		
		Result res = new Result();
		res.setSuccess(true);
		
		if(p.getId()==null){
			if(!this.projectService.addProject(p))
			{
				message =new String("添加失败！");
				res.setSuccess(false);
			}
		}else
		{
			if(!this.projectService.updateProject(p))
			{
				message =new String("更新失败！");
				res.setSuccess(false);
			}
		}
		res.setMessage(message);
		return  res;
	}
	
	/**
	 * 删除项目
	 * @param response
	 * @param id
	 * @return
	 */
	
	@RequestMapping(value="/delproject")
	public  @ResponseBody Object delProject(HttpServletResponse response , @RequestParam(value="id") int id)
	{
		response.setHeader("Accept",  "application/json");
		String message =new String("删除成功！");
		
		Result res = new Result();
		res.setSuccess(true);
		if(!this.projectService.delProject(id))
		{
			message =new String("删除失败！");
			res.setSuccess(false);
		}
		res.setMessage(message);
		return  res;
	}
}
